<template>
    <div style="">
        <h1 style="text-align:center">欢迎来到仓库管理系统</h1>
        <el-descriptions :title="'欢迎你! ' + admin.adminId" :column="2" size="40" :border="true">
            <el-descriptions-item>
                <template slot="label">
                    <i class="el-icon-s-custom">账号</i>
                </template>
                {{ admin.adminId }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label" >
                    <i class="el-icon-mobile-phone"></i>
                    邮箱
                </template>
                {{ admin.email }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    <i class="el-icon-mobile-phone"></i>
                    年龄
                </template>
                {{ admin.age }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    <i class="el-icon-mobile-phone"></i>
                    创建日期
                </template>
                {{ admin.createTime }}
            </el-descriptions-item>
            <el-descriptions-item>
                <template slot="label">
                    <i class="el-icon-mobile-phone"></i>
                    更新日期
                </template>
                {{ admin.updateTime }}
            </el-descriptions-item>
        </el-descriptions>
        <span style="text-align:center"><DateUtils></DateUtils></span>
    </div>
</template>

<script>
import DateUtils from "./DataUtils.vue";

export default {
    name: "HOme",
    components: {
        DateUtils
    },
    data() {
        return {
            admin: {
                adminId: "22",
                email: "",
                age: "",
                createTime: "",
                updateTime: "",
                isActive: "",
            }
        };
    },
    computed: {},
    created() {
        this.loadGet();
    },
    methods: {
        loadGet() {
            // 获取当前用户信息并解析
            const CurUser = JSON.parse(sessionStorage.getItem("CurUser") || '{}');
            
            if (CurUser && CurUser.adminId) {
                this.$axios.get(`http://localhost:8082/admin/${CurUser.adminId}`).then(response => {
                    this.admin = response.data.data;
                    console.log('Admin data:', this.admin); // 打印完整的admin对象来检查
                }).catch(error => {
                    console.error("Error loading admin data:", error);
                });
            } else {
                console.error("Current user information not found or invalid.");
            }
        }
    }
}
</script>